<?php include dirname(__FILE__).'/header.tpl.php'; ?>

<div id="ct" class="wp cl">
  <div class="mn">
    <div class="bm">
      <div class="bm_h">
        <h2>外卖菜谱</h2>
        <div class="menu_mode">
          <!--a href="/shop/<?=$shop['shop_id'];?>/index/menu" class="menu"><span>菜单</span></a-->
          <a href="/shop/<?=$shop['shop_id'];?>/index/foto" class="foto<? if($mode == 'foto') echo '-hover';?>"><span>图片</span></a> <a href="/shop/<?=$shop['shop_id'];?>/index/list" class="list<? if($mode == 'list') echo '-hover';?>"><span>列表</span></a> <a class="name">浏览模式：&nbsp;</a> </div>
      </div>
      <div class="bm_c">
        <?php
        if(empty($dishes)){
          echo '<p align="center" style="font-size:14px;"><br /><br /><br />暂无菜谱，具体情况请咨询店家！<br /><br /><br /><br /></p>';
        }else{
          include dirname(__FILE__)."/menu-{$mode}.tpl.php";
        }
      ?>
        <div class="clear"></div>
      </div>
    </div>
  </div>

  <div class="sd">
    <div class="bm <?php if($shop['status'] >=2){ ?>sdc1<?php } else { ?>sdc2<? } ?>">
      <div class="bm_h">
        <h2>我的订单</h2>
      </div>
      <div>
        <div id="mycart">
          <form method="post" action="/order/waimai" target="_blank" id="cartForm" >
            <input  type="hidden" name="dosubmit" value="yes" />
            <div class="r_mycart">
              <table cellspacing="0" cellpadding="0">
                <tbody>
                  <tr>
                    <th class="ttl">名称</th>
                    <th width="40">份数</th>
                    <th width="30">单价</th>
                    <th width="30">删除</th>
                  </tr>
                </tbody>
              </table>
              <p style="text-align:center;display:block;padding:20px 0;" id="noItemTips">您还没有添加菜品哦~</p>
              <table id="cartTable">
                <tbody>
                </tbody>
              </table>
              <input type="hidden" value="0" name="sum_price" id="sumPrice">
              <input type="hidden" value="<?=i($shop['shop_id']);?>" name="shop_id">
            </div>
            <div class="cart_o_total">
              <div class="my_all_total"><strong>总价钱：<span id="cartPrice">0</span></strong></div>
<?php
    $stat = '';
    if($shop['min_order']>0)       $stat = $shop['min_order'].'份起送，';
    elseif($shop['min_charge'] >0) $stat = $shop['min_charge'].'元起送，';

    if($shop['status'] == 2){
        $stat .= '网上订餐，餐到付款';
    }
    elseif($shop['status'] == 3){
        $stat .= '支持在线支付';
    }
    else{
        $stat .= '暂只支持电话订餐';
    }
?>
              <p class="b_s_tips">
                <?=h($stat);?>
              </p>
              <?php if($shop['status'] >=2){ ?>
              <div style="text-align:center;margin:5px;">
                <button class="cart_s_btn" type="submit" id="cart_btn"> 提交订单 </button>
              </div>
              <?php } ?>
            </div>
          </form>
        </div>
      </div>
    </div>

    <div class="bm sdc">
      <div class="bm_c">
        <h2>
          <?=h($shop['name']);?>
        </h2>
        <div class="feed_num cl">
          <ul>
            <li><a class="num" href="#">
              <?=$dish_count;?>
              </a></li>
            <li><a href="#">菜品</a></li>
          </ul>
          <ul style="border-left:1px dotted #ccc;border-right:1px dotted #ccc;">
            <li><a class="num" href="#">
              <?=$shop['likes'];?>
              </a></li>
            <li><a href="#">关注</a></li>
          </ul>
          <ul>
            <li><a class="num" href="#" id="views">
              <?=$shop['views'];?>
              </a></li>
            <li><a href="#">浏览</a></li>
          </ul>
        </div>
        <div id="call_number">
        <div>
              <b>订餐电话</b><br /><?=str_replace('/', '<br />', $order_call);?>
        </div>
        </div>
        <p style="color:#d00" onclick="$('#moreinfo').toggle()">
          <?php
            if($shop['status'] == 2){ $msg = '* 本店可通过网上、短信、电话订餐';}
            else if($shop['status'] == 3){ $msg = '* 本店支持网上支付、电话订餐';}
            else{$msg = '* 本店支持电话订餐、餐到付款';}
            echo $msg;
        ?>
        </p>
      </div>
      <div class="bm_c">
        <ul id="moreinfo">
          <li>
            <label>送餐时间：</label>
            <span>
            <?=h($shop['delivery_time']);?>
            </span> </li>
          <li>
            <label>送餐范围：</label>
            <span>
            <?=h($shop['delivery_desc']);?>
            </span> </li>
          <li></li>
          <li>
            <label>区 域：</label>
            <span> <a href="/waimai/<?=h($bigzone->pinyin);?>">
            <?=h($bigzone->name);?>
            </a> / <a href="/waimai/<?=h($subzone->pinyin);?>">
            <?=h($subzone->name);?>
            </a></span> </li>
          <li>
            <label>地 址：</label>
            <span>
            <?=h($shop['address']);?>
            </span> </li>
        </ul>
      </div>
      <div class="bm_h">
        <h2>地图</h2>
      </div>
      <div class="bm_c">
        <div id="baidu_map" style="width: 208; height: 208px;"></div>
      </div>
      <!--
      <div class="bm_h">
        <h2>微博</h2>
      </div>
      <div class="bm_c">
        <iframe width="100%" height="550" class="share_self" frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=550&fansRow=2&ptype=1&speed=0&skin=5&isTitle=0&noborder=0&isWeibo=1&isFans=1&uid=2607714464&verifier=fe5f84f0&dpc=1"></iframe>
      </div>
      -->
    </div>
  </div>
</div>
<div id="ol_contact"> <a class="online_se" onclick="openWin()" href="#">在线客服</a> </div>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2"></script>
<script type="text/javascript" src="<?=STATIC_URL;?>js/jquery-1.7.1.min.js"></script>
<!--script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script-->
<script type="text/javascript">
function openWin(){
    window.open('http://chat.53kf.com/company.php?arg=sudingke&style=1', 'kf53', 'height=450,width=510,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');
}
function initMap(lng, lat){
    var level = 16;

    if(!lng || !lat || lng == "0" || lat == "0"){
        lng = 121.623517;
        lat = 38.911717;
        level = 13;
    }

    var map = new BMap.Map("baidu_map");//在百度地图容器中创建一个地图
    var point = new BMap.Point(lng, lat);//定义一个中心点坐标

    map.enableDragging();//启用地图拖拽事件，默认启用(可不写)
    map.disableScrollWheelZoom();//启用地图滚轮放大缩小(可不写)
    map.enableDoubleClickZoom();//启用鼠标双击放大，默认启用(可不写)
    map.disableKeyboard();//禁用键盘上下左右键移动地图，默认禁用(可不写)

    map.centerAndZoom(point, level);
    map.panTo(point);

    //var iconimg = "http://api.map.baidu.com/library/MarkerTool/1.2/src/images/us_mk_icon.png";
    var iconimg = "<?=STATIC_URL;?>img/common/map_flag.gif";
    var icon = new BMap.Icon(iconimg, new BMap.Size(40, 43));

    //覆盖层
    var marker = new BMap.Marker(point);
    marker.setIcon(icon);

    map.addOverlay(marker);
}

function addCart(dishId){
    $.get("/shop/<?=h($shop['shop_id']);?>/ajax/dish-" +dishId,
        function(data){
            if(data.success){
                if($("#cart_" +data.dish_id).get(0)){
                    var num = $("#cart_" +data.dish_id).find("select").get(0);
                    if(num.selectedIndex < 9)
                        num.selectedIndex += 1;
                }else{
                    appendCart(data.dish_id, data.name, data.price);
                }
                totalPrice();
            }
        }, 'json'
    );

    function appendCart(dishId, dishName, dishPrice){
        var html = '';
        html += '<tr id="cart_' +dishId+ '">';
        html += '<td class="ttl">' +dishName+ '</td>';
        html += '<td width="40">';
        html += '<select class="cart_o_num" name="itemNum[' +dishId+ ']" onChange="totalPrice()">';
        for(var i=1; i<=10; i++){
            html += '<option value="' +i+ '">' +i+ '</option>';
        }
        html += '</select>';
        html += '</td>';
        html += '<td width="30" class="price">' +dishPrice+ '</td>';
        html += '<td width="30"><a href="javascript:delCart(' +dishId+ ');" class="del_btn">删除</a></td>';
        html += '</tr>';

        $("#cartForm").show();
        $("#cartTable").append(html);
        $("#noItemTips").hide();
    }
}

function delCart(dishId){
    $("#cart_"+dishId).remove();
    if($("#cartTable").find("tr").size() == 0){
        $("#noItemTips").show();
    }
    totalPrice();
}

function totalPrice(){
    var oItem = $("#cartTable").find("tr");
    var cnt   = oItem.size();
    var total = 0;
    oItem.each(function(){
        total += parseInt($(this).find("select").val(), 10) * parseFloat($(this).find(".price").html(), 10);
    });

    $("#cartPrice").html(total);
    $("#sumPrice").val(total);
}

$(document).ready(function() {
    $("#cartForm").submit(function(){
        if($("#sumPrice").val() == 0){
            alert("您还没有选择菜品");
            return false;
        }else{
            return true;
        }
    });

    $(".menu").find("li").mouseover(function(){
        $(this).addClass("hover");
    }).mouseout(function(){
        $(this).removeClass("hover");
    });

    if($(".menu_foto").get(0)){ //照片模式
        var $menu = $(".menu_foto").find(".menu");
        //$menu.hide();
        //$($menu.get(0)).show();

        var $catelink = $("ul.category").find("a");
        $($catelink.get(0)).addClass("current");

        $catelink.click(function(){
            $catelink.removeClass("current");
            $(this).addClass("current");

            var idx = $(this).attr("ref");
            if(idx == 'all'){
                $menu.show();
            }else{
                $menu.hide();
                $($menu.get(idx)).show();
            }
        });
    }

    //地图
    initMap("<?=doubleval($shop['longitude']);?>", "<?=doubleval($shop['latitude']);?>");
});

</script>
<!--浏览器数器-->
<script type="text/javascript" src="/tools/count?shop_id=<?=i($shop['shop_id']);?>&id=views" charset="utf-8"></script>
<?php include dirname(__FILE__).'/footer.tpl.php'; ?>
